package com.guoshengdeu.door.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoshengdeu.door.entity.ConfigBanner;
import com.guoshengdeu.door.service.IConfigBannerService;
import com.guoshengdeu.door.util.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yfly
 * @since 2021-06-01
 */
@Api("Banner配置")
@RestController
@RequestMapping("/config-banner")
public class ConfigBannerController {

    @Autowired
    private IConfigBannerService configBannerService;

    //查询banner
    @ApiOperation("查询")
    @RequestMapping("list")
    public List<ConfigBanner> queryBanner(){
        return configBannerService.list();
    }

    //添加更新
    @ApiOperation("添加更新")
    @RequestMapping("addbanner")
    public RespResult addBanner(@RequestBody ConfigBanner configBanner){
        boolean saveOrUpdate = configBannerService.saveOrUpdate(configBanner);
        if (saveOrUpdate){
            return RespResult.success();
        }
        return RespResult.error("添加或更新失败");
    }

    //删除banner
    @ApiOperation("删除")
    @DeleteMapping("delebanner")
    public RespResult deleBanner(int id){
        boolean removeById = configBannerService.removeById(id);
        if (removeById){
            return RespResult.success();
        }
        return RespResult.error("删除失败");
    }

    //分页
    @ApiOperation("分页")
    @GetMapping("page")
    public RespResult page(Page<ConfigBanner> page){
        Page<ConfigBanner> pages = configBannerService.page(page);
        return RespResult.success(pages);
    }

}
